package com.letwal.cmcvnd.aviewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import com.letwal.cmcvnd.adata.login.ReqLogin
import com.letwal.cmcvnd.adata.login.ReqRegister
import com.letwal.cmcvnd.base.BaseViewModel
import com.letwal.cmcvnd.anetwork.ApiUserReposity

class LoginViewModel : BaseViewModel() {

    //////////////////////////////////////////
    private val mDetectUserInfoLiveData = MutableLiveData<ReqLogin>()

    val onDetectUserInfoLiveData =
        Transformations.switchMap(mDetectUserInfoLiveData) { query ->
            ApiUserReposity.detectUserInfo(this, query)
        }

    fun detectUserInfo(reqLogin: ReqLogin) {
        mDetectUserInfoLiveData.value = reqLogin
    }

    //////////////////////////////////////////
    private val mLoginLiveData = MutableLiveData<ReqLogin>()

    val onLoginLiveData =
        Transformations.switchMap(mLoginLiveData) { query ->
            ApiUserReposity.login(this, query)
        }

    fun login(reqLogin: ReqLogin) {
        mLoginLiveData.value = reqLogin
    }

    //////////////////////////////////////////
    private val mRegisterLiveData = MutableLiveData<ReqRegister>()

    val onRegisterLiveData =
        Transformations.switchMap(mRegisterLiveData) { query ->
            ApiUserReposity.register(this, query)
        }

    fun register(reqRegister: ReqRegister) {
        mRegisterLiveData.value = reqRegister
    }

    //////////////////////////////////////////
    private val mRegisterConfirmLiveData = MutableLiveData<ReqRegister>()

    val onRegisterConfirmLiveData =
        Transformations.switchMap(mRegisterConfirmLiveData) { query ->
            ApiUserReposity.registerConfirm(this, query)
        }

    fun registerConfirm(reqRegister: ReqRegister) {
        mRegisterConfirmLiveData.value = reqRegister
    }
}